﻿using DBModels;
using System;
using System.Collections.Generic;
using System.Text;
using System.Linq;

namespace Method.DAL
{
    public static class GetMailByUid
    {
        /// <summary>
        /// 获取用户邮箱
        /// </summary>
        /// <param name="uid"></param>
        /// <returns>返回null为查无此人</returns>
        public static string GetMail(int uid)
        {
            //查询Redis
            var dataR = new RedisHelper.User.Mail().SelectMail(uid.ToString());
            if (dataR is null)
            {
                //查询数据库
                using (ArticeContext context = new ArticeContext()) {
                    var dataD = context.Accounts.FirstOrDefault(u => u.Id == uid);
                    if (dataD is null) 
                        return null;
                    return dataD.Mail;
                }
            }
            else
            {
                return dataR;
            }
        }
    }
}
